package shiyan3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListExample {
	public static void main(String[] args) {
		//1.创建ArrayList并添加元素
		List<String> list=new ArrayList<>();
		list.add("apple");
		list.add("banana");
		list.add("cherry");
		list.add("date");
		list.add("elderberry");
		
		//2.遍历ArrayList
		System.out.println("Original list:");
		for(String element:list) {
			System.out.println(element);
		}
		
		//3.使用Collections工具类对ArraryList进行排序
		Collections.sort(list);
		System.out.println("\nSorted list:");
		for(String element:list) {
			System.out.println(element);
		}
		
		//4.删除指定元素
		list.remove("cherry");
		System.out.println("\nList after removing 'cherry':");
		for(String element:list) {
			System.out.println(element);
		}
	}
}
